<?php

if (!defined('BASEPATH'))
     exit('No direct script access allowed');
/**
 * This class finds correspoding prices for rooms dataset
 * It extends price_row_finder so it is posibile to find prices of individual room
 * 
 * Must have serch inputs are
 * 
 * duration booking: Checkin, Checkout,
 * number of persons: Nr adults, Nr childrens
 * 
 * It automaticly finds corresponding season and period on each booking day
 *
 * @author ivankukic
 */
require_once(APPPATH . '/libraries/prices/price_row_finder.php');

class price_finder extends price_row_finder {

     private $rooms;

     public function __construct() {
          parent::__construct();
     }

     public function getRooms() {
          return $this->rooms;
     }

     public function setRooms($rooms) {
          $this->rooms = $rooms;
     }

     /**
      * 
      * Finds correspoding prices for rooms dataset
      * 
      * Must have serch inputs are:
      * 
      * - room_ID
      * 
      * @input dataset
      * 
      * [object_name] => Object 1
      * [destination_ID] => 2
      * [destination_name] => Budva
      * [room_type_name] => Single room
      * [room_ID] => 1
      * [room_description] => STANDARD
      * [room_max_person] => 1
      * [room_available_units] => 1
      * 
      * @return dataset
      * 
      * [object_name] => Object 1
      * [destination_ID] => 2
      * [destination_name] => Budva
      * [room_type_name] => Single room
      * [room_ID] => 1
      * [room_description] => STANDARD
      * [room_max_person] => 1
      * [room_available_units] => 1
      * [total_price] => 90
      * 
      */
     public function find_rooms_booking_prices() {
          $cnt = count($this->rooms);
          for ($i = 0; $i < $cnt; $i++):

               $this->setRoom_id($this->rooms[$i]['room_ID']);
               $price_row = $this->find_room_booking_price();

               // workaround if min_ng is not set
               if (empty($price_row)) {
                    unset($this->rooms[$i]); // do remove if no price
               } else {

                    $this->rooms[$i]['selling_price'] = $price_row['selling_price'];
                    $this->rooms[$i]['net_price'] = $price_row['net_price'];
                    $this->rooms[$i]['margin_price'] = $price_row['margin_price'];
                    $this->rooms[$i]['selling_total'] = $price_row['selling_total'];
                    $this->rooms[$i]['net_total'] = $price_row['net_total'];
                    $this->rooms[$i]['margin_total'] = $price_row['margin_total'];
               }
          endfor;

          return $this->rooms;
     }

}

?>